import request from '@/utils/request';
import type { Groupon, GrouponQuery, GrouponListData } from '@/types/groupon';

/**
 * 获取团购券列表
 */
export const fetchGroupons = (params: GrouponQuery) => {
  return request<GrouponListData>({
    url: '/v1/groupbuy',
    method: 'GET',
    data: params,
  });
};

/**
 * 获取团购券详情
 */
export const fetchGrouponDetail = (id: number) => {
  return request<Groupon>({
    url: `/v1/groupbuy/${id}`,
    method: 'GET',
  });
};

/**
 * 创建团购券
 */
export const createGroupon = (data: Partial<Groupon>) => {
  return request({
    url: '/v1/groupbuy',
    method: 'POST',
    data,
  });
};

/**
 * 更新团购券
 */
export const updateGroupon = (id: number, data: Partial<Groupon>) => {
  return request({
    url: `/v1/groupbuy/${id}`,
    method: 'PUT',
    data,
  });
};

/**
 * 删除团购券
 */
export const deleteGroupon = (id: number) => {
  return request({
    url: `/v1/groupbuy/${id}`,
    method: 'DELETE',
  });
};